package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.City;
import com.egao.orderB.service.CityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/city")
@RestController
@Api(value = "市",tags = {"市"})
public class ApiCityController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private CityService cityService;

    /**
     * 运费维护列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "市列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "返回的字段:\n" +
            "id:id\n" +
            "organizationId:组织id\n" +
            "cityId:id\n" +
            "city:名称\n" +
            "father:父id\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, City city, HttpServletRequest request)  throws Exception{
        return cityService.list(page, city, getLoginUser());
    }

    /**
     * 添加运费维护列表
     */
    @PostMapping("/listAll")
    @ApiOperation(value = "市列表",notes = "" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult listAll(City city, HttpServletRequest request)  throws Exception{
        return cityService.list(city, getLoginUser());
    }

    /**
     * 添加市
     */
    @OperLog(value = "市", desc = "添加市", result = true)
    @PostMapping("/save")
    @ApiOperation(value = "添加市",notes = "\n" +
            "cityId:id\n" +
            "city:名称\n" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult save(City city, HttpServletRequest request) {
        return cityService.save(city, getLoginUser());
    }


    /**
     * 修改市
     */
    @PreAuthorize("hasAuthority('orderB:city:update')")
    @OperLog(value = "市", desc = "修改市", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "修改市",notes = "" +
            "id:id 必填\n" +
            "cityId:id\n" +
            "city:名称\n" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult update(City city, HttpServletRequest request) {
        return cityService.update(city, getLoginUser());
    }

    /**
     * 删除市
     */
    @PreAuthorize("hasAuthority('orderB:city:remove')")
    @OperLog(value = "市", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "删除市",notes = "id:id必填",httpMethod = "POST")
    public JsonResult remove(City city, HttpServletRequest request) {
        return cityService.remove(city, getLoginUser());
    }

}
